package com.xiaoyang.common;

/**
 * @auther XiaoYang
 * @DATE 2022/12/11-17:37
 * 基于ThreadLocal封装的工具类，用于保存和获取当前登录的id
 */
public class BaseContext {
    private static final ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    /**
     * 设置id
     * @param id id
     */
    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }

    /**
     * 获取id
     * @return id
     */
    public static Long getCurrentId(){
        return threadLocal.get();
    }


    /**
     * 关闭线程
     */
    public static void close(){
        threadLocal.remove();
    }
}
